package org.linlinjava.litemall.db.service;

import org.linlinjava.litemall.db.dao.LitemallOrderMerchandiseMapper;
import org.linlinjava.litemall.db.domain.LitemallOrderMerchandise;
import org.linlinjava.litemall.db.domain.LitemallOrderMerchandiseExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class LitemallOrderMerchandiseService {
    @Resource
    private LitemallOrderMerchandiseMapper litemallOrderMerchandiseMapper;


    public LitemallOrderMerchandise findById(Integer id) {
        return litemallOrderMerchandiseMapper.selectByPrimaryKey(id);
    }


    public int add(LitemallOrderMerchandise record){
        record.setAddTime(LocalDateTime.now());
        record.setUpdateTime(LocalDateTime.now());
        return litemallOrderMerchandiseMapper.insertSelective(record);
        //return litemallOrderMerchandiseMapper.insert(record);
    }

    public int update(LitemallOrderMerchandise record){
    	record.setUpdateTime(LocalDateTime.now());
        return litemallOrderMerchandiseMapper.updateByPrimaryKeySelective(record);
    }
    
    public int deleteById(Integer id) {
        return litemallOrderMerchandiseMapper.deleteByPrimaryKey(id);
    }
    
    public int deleteByOrderId(Integer orderId) {
    	LitemallOrderMerchandiseExample example = new LitemallOrderMerchandiseExample();
        example.or().andOrderIdEqualTo(orderId).andDeletedEqualTo(false);
    	return litemallOrderMerchandiseMapper.deleteByExample(example);
    }
    
    public int deleteByOrderIdAndOrderGoodsId(Integer orderId, Integer orderGoodsId) {
    	LitemallOrderMerchandiseExample example = new LitemallOrderMerchandiseExample();
    	example.or().andOrderIdEqualTo(orderId).andOrderGoodsIdEqualTo(orderGoodsId).andDeletedEqualTo(false);
    	return litemallOrderMerchandiseMapper.deleteByExample(example);
    }
    
    public List<LitemallOrderMerchandise> queryByOrderIdAndOrderGoodsId(Integer orderId, Integer orderGoodsId){
    	LitemallOrderMerchandiseExample example = new LitemallOrderMerchandiseExample();
    	example.or().andOrderIdEqualTo(orderId).andOrderGoodsIdEqualTo(orderGoodsId).andDeletedEqualTo(false);
        return litemallOrderMerchandiseMapper.selectByExample(example);
    }
}
